package com.ly.demo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class LoginController {
    @GetMapping("/login")
    public String toLogin() {
        return "login";
    }

    @PostMapping("/login")
    public String login(HttpServletRequest request, String userName, String userPassword) {
        if (userName.equals("admin") && userPassword.equals("admin")) {
            request.getSession().setAttribute("loginUser", "admin");
            return "redirect:main";
        }
        return "redirect:/login";
    }
    @GetMapping("/main")
    public String main() {
        return "main";
    }
}
